#include<bits/stdc++.h>
using namespace std;
struct P{
    long long d,v,a;
};
struct P2{
    int wz,jcsl;
};
bool cmp(P2 a,P2 b)
{
    return a.wz > b.wz;
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin >> t;
    while(t--)
    {
        int n,m,l,v;
        cin >> n >> m >> l >> v;
        P a[n+1];
        bool f[n+1];
        memset(f,0,sizeof(f));
        P2 q[m+1];
        int s = 0;
        for(int i = 1;i <= n;i++)
        {
            cin >> a[i].d >> a[i].v >> a[i].a;
            s += a[i].a;
        }
        int sum = 0;
        int s2 = 0;
        if(s == 0)
        {
            for(int i = 1;i <= m;i++)
            {
                cin >> q[i].wz;
            }
            sort(q+1,q+m+1,cmp);
            for(int i = 1;i <= m;i++)
            {
                q[i].jcsl=0;
                for(int j = 1;j <= n;j++)
                {
                    if(a[j].d <= q[i].wz && a[j].v >= v)
                    {
                        if(!f[j])
                        {
                            sum++;
                            q[i].jcsl++;
                        }
                        f[j] = true;
                    }
                }
                if(q[i].jcsl == 0)
                {
                    s2++;
                }
            }
        }
        else
        {
            for(int i = 1;i <= m;i++)
            {
                cin >> q[i].wz;
            }
            sort(q+1,q+m+1,cmp);
            for(int i = 1;i <= m;i++)
            {
                q[i].jcsl=0;
                for(int j = 1;j <= n;j++)
                {

                    if(a[j].d <= q[i].wz && ceil(sqrt(a[j].v * a[j].v + 2 * (q[i].wz-a[j].d)*a[j].a) > v))
                    {
                        if(!f[j])
                        {
                            sum++;
                            q[i].jcsl++;
                        }
                        f[j] = true;
                    }
                }
                if(q[i].jcsl == 0)
                {
                    s2++;
                }
            }
        }
        cout << sum << " " << s2 << endl;
    }
    return 0;
}
